import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'

import type { ConfigEnv } from 'vite'

// eui
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'

// https://vite.dev/config/
export default defineConfig(({ mode }: ConfigEnv) => {
  const env = loadEnv(mode, process.cwd(), 'VITE')
  console.log(env);


  return {
    plugins: [
      vue(),
      ElementPlus({}),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    resolve: {
      alias: {
        '@': resolve('src'),           // src 根目录
      },
    },
    server: {
      port: 12345,
      proxy: {
        '/api': {
          target: env.VITE_HOST_URL,//目标服务器地址
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
        '/ws': {
          target: env.VITE_HOST_URL,
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(/^\/ws/, '')
        }
      },
    },
    build: {
    }
  }
})



